package com.huang.view.common;

import java.util.List;

import com.huang.R;


import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageButton;
import android.widget.TextView;

public class MyListAdapter extends BaseAdapter {

	private LayoutInflater mInflater;   
    private Context mContext = null;
    private List<String> items;
    
    public MyListAdapter(Context context,List<String> items) {   
        this.mContext = context;
        this.items = items;
        mInflater = LayoutInflater.from(mContext);   
    }
    
    public class ViewHolder {
		TextView mTextView;
		ImageButton mIcon;
	}
    
    public Object getItem(int arg0) {   
        // TODO Auto-generated method stub   
        return items.get(arg0);   
    }   
    public long getItemId(int position) {   
        // TODO Auto-generated method stub   
        return position;   
    }   
    public int getCount() {   
        // TODO Auto-generated method stub   
        return items.size();   
    }   
    public View getView(int position, View convertView,   
            android.view.ViewGroup parent) {           
        final ViewHolder holder;
		if (convertView == null) {
			// 使用XML文件填充整个布局
			convertView = mInflater.inflate(R.layout.music_list_adapter, null);
			// 生成存放数据的组件模型
			holder = new ViewHolder();
			holder.mTextView = (TextView) convertView.findViewById(R.id.tv_title);
			holder.mIcon = (ImageButton) convertView.findViewById(R.id.index_image);
			//将存放数据的组件模型加入到整个View视图中
			convertView.setTag(holder);
		}else{
			holder = (ViewHolder) convertView.getTag();}
        
        // 设置item中ImageView的图片   
		holder.mIcon.setBackgroundResource(R.drawable.image_face);
		holder.mTextView.setText(items.get(position).toString());
        return convertView;   
    }
} 
